package com.xiang.producer;

import com.xiang.RabbitmqApplication;
import com.xiang.config.FanoutConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;

/**
 * Fanout广播模式
 *
 * @author: xiangtianlei
 * @Date: 2022-9-10
 */
@SpringBootTest(classes = RabbitmqApplication.class)
@RunWith(SpringRunner.class)
public class ProducerFanoutTest {

    @Resource
    RabbitTemplate rabbitTemplate;

    @Test
    public void SendMessage() {
        //  routingKey:key为空,将消息发送到交换机，交换机发送到每一个队列中,监听队列的消费者都能获取到消息
        rabbitTemplate.convertAndSend(FanoutConfig.FANOUT_EXCHANGE, "", "通过交换机广播到每一个队列");
    }
}
